package robotleMvc.frameworks.uiContainers
{

	import com.ui.layout.GLayout;

	import org.robotlegs.mvcs.Mediator;

	import robotleMvc.frameworks.buildEdit.BuildEditMediator;
	import robotleMvc.frameworks.buildEdit.event.BuildEditEvent;
	import robotleMvc.frameworks.dispcontainer.DispcontainerEvent;
	import robotleMvc.frameworks.dispcontainer.DispcontainerMediator;
	import robotleMvc.frameworks.topMenu.TopMenuMediator;
	import robotleMvc.ui.buildEdit.BuildEditView;
	import robotleMvc.ui.dispcontainer.DispcontainerView;
	import robotleMvc.ui.topMenu.TopMenuView;
	import robotleMvc.ui.uiContainers.UiContainer;

	// --------------MSN:lation_pan@live.cn  QQ: 3423526------------- //
	public class UiContainerMediator extends Mediator
	{
		[Inject]
		public var uiContainer:UiContainer;
		private var _topMenuView:TopMenuView;
		private var _dispcontainerView:DispcontainerView;
		private var _buildEditView:BuildEditView;

		override public function onRegister():void
		{
			mapView();
			addDispcontainerView();
			addEvents();

		}

		private function addEvents():void
		{
			this.addContextListener(DispcontainerEvent.OPEN_TOP_VIEW, openTopView)
			this.addContextListener(BuildEditEvent.OPEN_BUILD_EDIT_VIEW, openBuildEditView)

		}

		private function openBuildEditView(evt:BuildEditEvent):void
		{
			if (_buildEditView && _buildEditView.parent)
			{
				_buildEditView.hide();
			}
			else
			{
				_buildEditView=new BuildEditView(uiContainer.windowsLevel);
				_buildEditView.show();
				GLayout.layout(_buildEditView);
			}

		}

		private function openTopView(dispcontainerEvent:DispcontainerEvent):void
		{
			if (_topMenuView && _topMenuView.parent)
			{
				_topMenuView.hide();
			}
			else
			{
				_topMenuView=new TopMenuView(uiContainer.windowsLevel);
				_topMenuView.show();
				GLayout.layout(_topMenuView);
			}

		}

		private function addDispcontainerView():void
		{
			_dispcontainerView=new DispcontainerView();
			uiContainer.addChild(_dispcontainerView);

		}

		private function mapView():void
		{
			mediatorMap.mapView(TopMenuView, TopMenuMediator);
			mediatorMap.mapView(DispcontainerView, DispcontainerMediator);
			mediatorMap.mapView(BuildEditView, BuildEditMediator);
		}
	}
}
